//fragment shader for filter on X direction 
uniform sampler2D tex;
uniform int size;
uniform float pr;

const float PI = 3.14159265358;

void main(void)
{
	// Texture coordinates 
	float s = gl_TexCoord[0].s ;
	float t = gl_TexCoord[0].t ;

	float kr = pr * float(size);
	float da = PI / kr;
	int r = int(kr);
	vec3 h = vec3(0.5, 0.5, 0.0);
	float offset, theta;
	
	for (int i = -r; i <= r; i++) {
		offset = float(i) / float(size);
		theta = da * float(i);
		h.x += texture2D(tex, vec2(s + offset, t)).z * 0.5 * (cos(theta) + 1.0) * sin(theta);
		h.y += texture2D(tex, vec2(s, t + offset)).z * 0.5 * (cos(theta) + 1.0) * sin(theta);
		h.z += texture2D(tex, vec2(s + offset, t)).z * 0.5 * (cos(theta) + 1.0);
	}
	
	gl_FragColor = vec4(h, 1.0);
}
